In the pull data provision model, you write a method that fulfills the OPC Read requests (and optionally subscription updates) by interrogating the underlying system, and returns the data that should be given to the OPC client. The OPC Wizard calls your method when needed (pulls the data).
This is the more common data provision model.
Your task as a developer is to provide the code for handling the Read request by either adding an event handler for the Read Event, or overriding the OnRead Method. The code for handling the data pull can be attached to each data variable separately, or you can use a common code on some higher level in the tree of the server nodes - for example, a folder can have code that handles all Reads for the data variables contained in the folder.
In order to indicate that you have handled the Read request, your code will call the HandleAndReturn Method on the event arguments object. Note that if you use the extension methods for configuration of data variables, the event handler added by the extension methods already does this for you.
The following picture illustrates how the pull data provision model works.
The OPC Wizard provides extension methods that allow you to define data variables that use the pull data provision model easily, without having to deal with method overrides, or handle events. This is described in the Data Variable Configuration article. Typically, you will use some overload of the ReadFunction or ReadValueFunction method to configure the data variable for the pull data provision model. With these methods, you use .NET functions (Func Delegate) to specify the code that handles the request. The following example illustrates the use of the ReadValueAction method.
How do you choose between these extension methods?
The following example illustrates the use of the ReadFunction method for returning data with a timestamp specified in your code.
The following example illustrates the use of the ReadFunction method for returning data with a status code generated in your code.
If your OPC server has groups of data variables with basically the same behavior, and organized in such a way that it corresponds to the node space hierarchy, you would probably want to specify the behavior just once, e.g. on the level of the folder that holds all data variables of the same kind. In such case, you cannot use the extension methods for data variable configuration (described above), and need to define the behavior by handling the Read Event, or overriding the OnRead Method, on the higher level - in our example, the level of the folder. The following examples illustrate these approaches.
Example: Examples - Server OPC UA - Implement variable reading on folder level, with an event
Example: Examples - Server OPC UA - Implement variable reading on folder level, with inheritance
See Variable Data Type Considerations.